
#创建一个浏览器对象
import datetime
import os.path
import sys

import datetime
import time
from sys import executable

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
# from webdriver_manager.chrome import ChromeDriverManager
# from webdriver_manager.drivers.edge import EdgeChromiumDriver

class Driver:
    driver = ""
    def __init__(self):
        options = webdriver.EdgeOptions()
        edge_driver_path = r"D:\driver\edgedriver_win64\msedgedriver.exe"
        service = Service(edge_driver_path)
        self.driver = driver=webdriver.Edge(service=service,options=options)
        self.driver.implicitly_wait(2)
    def getScreeShot(self):
        #创建屏幕截图
        #图片文件名称：./2024-05-08-173456.png
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否已经存在，若不存在则创建文件夹
        # ../images/2024-05-08
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        #2024-05-08-173456.png
        #图片路径:../images/调用方法-2024-05-08/2024-05-08-173456.png
        #图片路径:../images/LoginSucTest-2024-05-08/2024-05-08-173456.png
        #图片路径:../images/LoginFailTest-2024-05-08/2024-05-08-173456.png
        filename = sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

ForumDriver = Driver()